<!DOCTYPE html>
<html lang='zh-CN'>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
    <title>店铺优惠管理</title>
    <link rel="icon" href="favicon.ico" type="image/ico">
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/materialdesignicons.min.css" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.min.css" rel="stylesheet">
    <link href="js/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link rel="stylesheet" href="js/bootstrap-datetimepicker/bootstrap-datetimepicker.min.css">
    <!--时间选择插件-->
    <link rel="stylesheet" href="js/bootstrap-datetimepicker/bootstrap-datetimepicker.min.css">
    <!--日期选择插件-->
    <link rel="stylesheet" href="js/bootstrap-datepicker/bootstrap-datepicker3.min.css">
    <link href="css/style.min.css" rel="stylesheet">


</head>
<body>
<div class="container-fluid p-t-15">

    <div class="row">
        <div class="col-lg-12">
            <div class="card">
                <div class="card-header">

                    <div id="toolbar" class="toolbar-btn-action">
                        <form class="form-inline" method="post" id="searchForm">
                            <div class="form-group">
                                <label>优惠活动时间:</label>
                                <input type="text" class="form-control js-datepicker" data-date-format="yyyy-mm-dd" name="startTime" placeholder="开始时间"> -
                                <input type="text" class="form-control js-datepicker" data-date-format="yyyy-mm-dd" name="endTime" placeholder="结束时间">
                            </div>
                            <div class="form-group">
                                <button class="btn btn-info btn_query btn-round" type="button" id="searchFormBtn">查询</button>
                            </div>
                            <div class="form-group">
                                <button class="btn btn-success btn_query btn-round" type="button" id="addBtn">添加</button>
                            </div>
                            <div class="form-group">
                                <button class="btn btn-warning btn_query btn-round" type="button" id="editBtn">编辑</button>
                            </div>
                            <div class="form-group">
                                <button class="btn btn-purple btn_query btn-round" type="button" id="activation" onclick="changeStatus(1)">激活</button>
                            </div>
                            <div class="form-group">
                                <button class="btn btn-danger btn_query btn-round" type="button" id="Logout" onclick="changeStatus(0)">注销</button>
                            </div>
                        </form>
                    </div>

                </div>
                <div class="card-body">
                    <table id="coupon_data"></table>
                </div>
            </div>
        </div>
    </div>

    <!--  添加与编辑模态框 -->
    <div class="modal fade" id="addOrEditModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="exampleModalLabel">店铺优惠管理</h4>
                </div>
                <div class="modal-body">
                    <form id="addOrEditForm" action="/system/role/addOrEditRole" method="post" data-target="validator">
                        <div class="row">
                            <div class="col-xs-6">
                                <input type="hidden" name="id">
                                <label for="fullPrice" class="control-label">满：</label>
                                <input type="text" class="form-control" id="fullPrice" name="fullPrice" required>
                            </div>
                            <div class="col-xs-6">
                                <label for="reducePrice" class="control-label">减：</label>
                                <input type="text" class="form-control" id="reducePrice" name="reducePrice" required>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label">开始时间：</label>
                            <div class="col-sm-12">
                                <input class="form-control js-datetimepicker" type="text" id="startTime" name="startTime" placeholder="请选择具体时间" value="" data-side-by-side="true" data-locale="zh-cn" data-format="YYYY-MM-DD HH:mm:ss" />
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="control-label">结束时间：</label>
                            <div class="col-sm-12">
                                <input class="form-control js-datetimepicker" type="text" id="endTime" name="endTime" placeholder="请选择具体时间" value="" data-side-by-side="true" data-locale="zh-cn" data-format="YYYY-MM-DD HH:mm:ss" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label">板块类型：</label>
                            <div>
                                <label class="checkbox-inline i-checks"> <input type="radio" name="addOther" value="0"/>自营</label>
                                <label class="checkbox-inline i-checks"> <input type="radio" name="addOther" value="1"/>通用</label>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                            <button type="button" class="btn btn-primary" id="sava">保存</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>


    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript" src="js/bootstrap.min.js"></script>
    <script type="text/javascript" src="js/bootstrap-table/bootstrap-table.js"></script>
    <script type="text/javascript" src="js/bootstrap-table/bootstrap-table-zh-CN.min.js"></script>
    <script type="text/javascript" src="js/zero2one/zero2one.version.js"></script>
    <script type="text/javascript" src="js/zero2one/zero2one.core.js"></script>
    <!-- bootstrap表单验证插件 -->
    <script type="text/javascript" src="js/bootstrap-validator-master/dist/validator.js"></script>
    <!-- jquery-form表单提交插件 -->
    <script type="text/javascript" src="js/jquery-form/jquery.form.js"></script>
    <!-- bootstrap弹出框插件 -->
    <script type="text/javascript" src="js/jquery.bootstrap.min.js"></script>
    <!--时间选择插件-->
    <script src="js/bootstrap-datetimepicker/moment.min.js"></script>
    <script src="js/bootstrap-datetimepicker/bootstrap-datetimepicker.min.js"></script>
    <script src="js/bootstrap-datetimepicker/locale/zh-cn.js"></script>
    <!--日期选择插件-->
    <script src="js/bootstrap-datepicker/bootstrap-datepicker.min.js"></script>
    <script src="js/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js"></script>
    <script type="text/javascript" src="js/main.min.js"></script>
    <!-- 表单填充插件 -->
    <script type="text/javascript" src="js/jquery-form/jquery.formloader.js"></script>

    <script type="text/javascript">

        //设置表头
        var columns = [
            {checkbox: true},
            {field: 'id',title: 'ID'},
            {field: 'businessId',title: '商家id',visible: false},
            {field: 'fullPrice',title: '满'},
            {field: 'reducePrice',title: '减'},
            {field: 'startTime',title: '开始时间',formatter: function (value) {
                    return zero2one.dateFormat(value, 'Y-m-d H:i:s')
                }},
            {field: 'endTime',title: '结束时间',formatter: function (value) {
                    return zero2one.dateFormat(value, 'Y-m-d H:i:s')
                }},
            {field: 'addOther',title: '板块类型',formatter: function (value, row, index) {
                    if (value=='0') {
                        return "自营";
                    }else if(value=='1'){
                        return "通用";
                    }}},
            {field: 'publish',title: '发布状态',formatter: function (value, row, index) {
                    if (value=='1') {
                        return "发布";
                    }else if(value=='0'){
                        return "未发布";
                    }}},
        ];

        //进入主界面加载数据
        zero2one.datagrid("coupon_data", "/remote/couponbusiness/couponBusinessList",function (params) {
            return $.extend(zero2one.tableInitParam(params), zero2one.form2json("searchForm"));
        }, columns);

        //点击查询按钮重新加载页面数据
        $("#searchFormBtn").click(function () {
            $('#coupon_data').bootstrapTable('refresh');
        });

        //点击添加按钮弹出模态框
        $("#addBtn").click(function () {
            $("#addOrEditModal").modal("show");
            $(":radio[name='addOther'][value='0']").prop("checked", "checked");
        });

        //点击编辑按钮弹出模态框
        $("#editBtn").click(function () {

            //获取选中行的数据
            var datas = $('#coupon_data').bootstrapTable('getSelections');
            console.log(datas);
            //判断是否选中行数据，如果没有则提示
            if(datas.length == 1){
                //填充表单
                $("#addOrEditForm").formloader({data: datas[0]});

                $(":radio[name='addOther'][value='" + datas[0].addOther + "']").prop("checked", "checked");
            }else{
                $.messager.alert("温馨提示", "请选择一条数据操作");
                return;
            }

            $("#addOrEditModal").modal("show");
        });

        //保存按钮的点击事件
        $("#sava").click(function () {
            zero2one.request("/remote/couponbusiness/addOrEditCoupon",$("#addOrEditForm").serialize(),function (data) {
                if (data.success) {
                    window.location.reload();
                }else {
                    $.messager.alert("温馨提示", data.msg)
                }
            });
        });

        //编辑板块状态
        function changeStatus(publish) {
            //获取选中行的数据
            var datas = $('#coupon_data').bootstrapTable('getSelections');
            //判断是否选中行数据，如果没有则提示
            if(datas.length > 0){
                $.messager.confirm("温馨提示", "您确定要更改用户状态吗?", function () {
                    //发送请求,执行批量删除
                    $.post("/remote/couponbusiness/changeStatus", {"publish" : publish,"ids" : zero2one.array2str(datas)},
                        function(data){
                            if (data.success) {
                                window.location.reload();
                            } else {
                                $.messager.alert("温馨提示", data.msg)
                            }
                        }, "json");
                })
            }else{
                $.messager.alert("温馨提示", "请至少选择一条数据操作");

            }
        }

    </script>

</div>
</body>
</html>
